package com.bnlr.lrparking.appui.unused;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioGroup.LayoutParams;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.view.HackyViewPager;
import com.bnlr.lrparking.util.ActivityStack;

import java.util.ArrayList;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
 * 图片轮播显示
 * 当前未使用  2018-11-27
 */
public class DaTuLunBoActivity extends BaseActivity {
    private HackyViewPager mViewPager;
    private static ArrayList<String> list = new ArrayList<String>();
    private int tag = 0;
    private TextView datu_shu;
    private static Context mContext = null;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_lunbo_datu);
        mViewPager = (HackyViewPager) findViewById(R.id.img_bg);
        datu_shu = (TextView) findViewById(R.id.datu_shu);
        list = getIntent().getStringArrayListExtra("TuPian");
        tag = getIntent().getIntExtra("tag", 0);
        mContext = DaTuLunBoActivity.this;
        mViewPager.setAdapter(new SamplePagerAdapter());
        mViewPager.setCurrentItem(tag);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                datu_shu.setText((position + 1) + "/" + list.size());
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    static class SamplePagerAdapter extends PagerAdapter {
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            photoView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            Glide.with(mContext).load(list.get(position)).placeholder(R.mipmap.icon_moren).error(R.mipmap.icon_moren).into(photoView);
//			// Now just add PhotoView to ViewPager and return it
            container.addView(photoView, LayoutParams.MATCH_PARENT,
                    LayoutParams.MATCH_PARENT);
            photoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
                @Override
                public void onPhotoTap(View view, float x, float y) {
                    try {
                        ActivityStack.getScreenManager().popOneActivity(DaTuLunBoActivity.class);
                    } catch (Exception e) {

                    }
                }

                @Override
                public void onOutsidePhotoTap() {

                }
            });
            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }
}
